cmake_minimum_required( VERSION 2.8 )
project(px4_control_module)

set( CMAKE_CXX_FLAGS "-std=c++14" )

set(CMAKE_C_FLAGS "-pthread -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-pthread")
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")

execute_process(COMMAND uname -m
        OUTPUT_VARIABLE DEVICE_SYSTEM_ID)
message(WARNING " device system id: ${DEVICE_SYSTEM_ID}")

if (DEVICE_SYSTEM_ID MATCHES x86_64)
    add_definitions(-DPLATFORM_ARCH_x86_64=1)
elseif (DEVICE_SYSTEM_ID MATCHES aarch64)
    add_definitions(-DPLATFORM_ARCH_aarch64=1)
else ()
    message(FATAL_ERROR "FATAL: Please confirm your platform.")
endif ()


set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/3rdparty)

find_package( OpenCV 4 REQUIRED)
add_definitions(-DOPENCV4)


find_package(FFMPEG REQUIRED)


# for ekf type , here use Pdot = F * P * F' + Q
add_definitions(-DEKF_UPDATE_DISCRETE)

include_directories( 
	src
	mavlink_build/include/mavlink
	src/circularBuf
	src/mountSiyi
	src/pid
	src/ekf
	src/mountPinling
  	${OpenCV_INCLUDE_DIRS}
  	${FFMPEG_INCLUDE_DIR}
  )

add_library(circular_buf STATIC src/circularBuf/circular_buf.cpp)
add_library(pid STATIC src/pid/pid.cpp)
add_library(ekf STATIC src/ekf/ekf.cpp  src/ekf/matrix.cpp)


add_executable(px4_control_module  	src/main.cpp
									src/px4_flight_handler.cpp)


target_link_libraries( px4_control_module  	${OpenCV_LIBS}
											${FFMPEG_LIBRARIES}
											circular_buf
											pid
											ekf)


